
capture use "data files/sen_r5_local.dta", clear

gen year_survey = 2013

gen round = 5

***********************
***   Demographic   ***
***********************

decode urbrur, gen(urb)
drop urbrur
ren urb urbrur

* Age
gen age = Q1 
label var age "Age of respondent"
replace age=. if age==-1 | age==999 

*Gender
decode Q101, gen(gender)
label var gender "Gender of respondent"
drop Q101

*Education

gen no_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace no_school = 1 if Q97==0 
label var no_school "No formal schooling"
gen informal_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace informal_school = 1 if Q97==1 & Q97<=9
label var informal_school "Informal schooling only"

gen primary_school_inc = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace primary_school_inc = 1 if Q97>=2 & Q97<=9
gen primary_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace primary_school = 1 if Q97>=3 & Q97<=9
gen secondary_school_inc = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace secondary_school_inc = 1 if Q97>=4 & Q97<=9
gen secondary_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace secondary_school = 1 if Q97>=5 & Q97<=9
gen college = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace college = 1 if Q97>=7 & Q97<=9
label var college "Some college, even if incomplete"
drop Q97

*Religion
gen religion=""
replace religion="None" if Q98A==0 | Q98A==28 | Q98A==29
replace religion="Muslim" if (Q98A>=18 & Q98A<=24)
replace religion="Christian" if (Q98A>=1 & Q98A<=13 ) | (Q98A>=30 & Q98A<=33) | Q98A==16 
replace religion="Traditional" if Q98A==25
replace religion="Other" if Q98A==14  | Q98A==15  | Q98A==17 | Q98A==34
replace religion="Unkown" if Q98A==9995  | Q98A==9998  | Q98A==-1 | Q98A==9999
tab Q98A if religion==""

gen ethnicity = Q2
replace ethnicity = . if Q2 >= 9996 | Q2 < 0

gen wolof = 0 if ethnicity != .
replace wolof = 1 if ethnicity == 660

gen toucpeul = 0 if ethnicity != .
replace toucpeul = 1 if ethnicity == 661

gen serer = 0 if ethnicity != .
replace serer = 1 if ethnicity == 662

gen bambara = 0 if ethnicity != .
replace bambara = 1 if ethnicity == 663

gen soninke = 0 if ethnicity != .
replace soninke = 1 if ethnicity == 664

gen diola = 0 if ethnicity != .
replace diola = 1 if ethnicity == 665

gen others = 0 if ethnicity != .
replace others = 1 if ethnicity == 668 | ethnicity == 9995 | ethnicity == 666


gen language = Q2

gen french_lang = 0 if language != .
replace french_lang = 1 if language == 2

gen wolof_lang = 0 if language != .
replace wolof_lang = 1 if language == 660

gen toucpeul_lang = 0 if language != .
replace toucpeul_lang = 1 if language == 661

gen serer_lang = 0 if language != .
replace serer_lang = 1 if language == 662

gen mand_lang = 0 if language != .
replace mand_lang = 1 if language == 663 

gen diola_lang = 0 if language != .
replace diola_lang = 1 if language == 665

gen other_lang = 0 if lang != .
replace other_lang = 1 if wolof_lang == 0 & toucpeul_lang == 0 & serer_lang == 0 & mand_lang == 0 & diola_lang == 0


********************
***   Economic   ***
********************

gen no_food = 0 if Q8A!=-1 & Q8A!=. & Q8A!=9
replace no_food = 1 if Q8A==2 | Q8A==3 | Q8A==4

gen no_water = 0 if Q8B!=-1 & Q8B!=. & Q8B!=9
replace no_water = 1 if Q8B==2 | Q8B==3 | Q8B==4

gen no_healthcare = 0 if Q8C!=-1 & Q8C!=. & Q8C!=9
replace no_healthcare = 1 if Q8C==2 | Q8C==3 | Q8C==4

gen no_fuel = 0 if Q8D!=-1 & Q8D!=. & Q8D!=9
replace no_fuel = 1 if Q8D==2 | Q8D==3 | Q8D==4

gen no_income = 0 if Q8E!=-1 & Q8E!=. & Q8E!=9
replace no_income = 1 if Q8E==2 | Q8E==3 | Q8E==4
drop Q8A - Q8E


gen employment_status = "" if Q96!=. & Q96!=-1 & Q96!=9
replace employment_status = "inactive" if  Q96==0
replace employment_status = "unemployed" if Q96==1
replace employment_status = "part-time" if Q96==2
replace employment_status = "full-time" if Q96==3
drop Q96

*** Assets *** 

gen owns_radio = 0 if Q90A!=. & Q90A!=-1 & Q90A!=9
replace owns_radio = 1 if Q90A==1

gen owns_tv = 0 if Q90B!=. & Q90B!=-1 & Q90B!=9
replace owns_tv = 1  if Q90B==1

gen owns_vehicle = 0 if Q90C!=. & Q90C!=-1 & Q90C!=9
replace owns_vehicle = 1  if Q90C==1


**************************
***   Interest index   ***
**************************


gen discuss_pol_index = Q15 if Q15 >= 0 & Q15 <= 2 

gen interest_pub_affairs_index = 0 if Q14!=-1 & Q14!=. & Q14!=9
replace interest_pub_affairs_index = 1 if Q14==2 | Q14==3
replace interest_pub_affairs_index = 2 if Q14==3


**** Information and Media ***

gen radio = Q13A if Q13A!=-1 & Q13A!=. & Q13A!=9 & Q13A != 998
gen tv = Q13A if Q13B!=-1 & Q13B!=. & Q13B!=9 & Q13B != 998
gen newspaper = Q13C if Q13C!=-1 & Q13C!=. & Q13C!=9 & Q13C != 998
gen internet = Q13D if Q13D!=-1 & Q13D!=. & Q13D!=9 & Q13D != 998

gen radio_news_often =0 if Q13A!=-1 & Q13A!=. & Q13A!=9
replace  radio_news_often =1 if Q13A==4

gen tv_news_often =0 if Q13B!=-1 & Q13B!=. & Q13B!=9
replace  tv_news_often =1 if Q13B==4

gen newspaper_news_often =0 if Q13C !=-1 & Q13C !=. & Q13C !=9
replace  newspaper_news_often =1 if Q13C ==4

gen internet_news_often =0 if Q13D !=-1 & Q13D !=. & Q13D !=9
replace  internet_news_often =1 if Q13D ==4


*************************
***   Participation   ***
*************************

gen contact_LG_councilor_index = Q30A if Q30A!=. & Q30A!=-1 & Q30A!=9 & Q30A != 998

gen contact_MP_index = Q30B if Q30B!=. & Q30B!=-1 & Q30B!=9 & Q30B != 998

gen contact_officials_index = Q30C if Q30C!=. & Q30C!=-1 & Q30C!=9 & Q30C != 998

gen att_demonstration_index = Q26D if Q26D!=. & Q26D!=-1 & Q26D!=9 & Q26D != 998

gen raise_issue_index = Q26B  if Q26B!=. & Q26B!=-1 & Q26B!=9 & Q26B != 98

gen vote1 = 0 if Q27 !=-1 & Q27 !=9 &  Q27 !=.
replace vote1 = 1 if Q27==1

gen close_pds = 0 if Q89B <= 9997 & Q89B != . & Q89B != -1
replace close_pds = 1 if Q89B == 660


***********************************
***   Democratic institutions   ***
***********************************

*NEEDS TO BE CHECKED /

gen trust_EC= Q59C if Q59C!=. & Q59C!=-1 &  Q59C!=9
gen trust_courts=Q59J if Q59J !=. & Q59J !=-1 & Q59J!=9
gen careful_say = Q56A if Q56A !=. & Q56A!= -1 & Q56A!=9 
gen elections_free_fair = Q28 if Q28 < 8 & Q28 >= 0

gen free_to_speak_mind= 0 if Q17A!=. &   Q17A!=-1
replace free_to_speak_mind= 1 if Q17A==3
replace free_to_speak_mind= 2 if Q17A==4

gen free_to_join_pol_org= 0 if Q17B!=. &   Q17B!=-1
replace free_to_join_pol_org= 1 if Q17B==3
replace free_to_join_pol_org= 2 if Q17B==4

gen free_vote_choice= 0 if Q17C!=. &   Q17C!=-1
replace free_vote_choice= 1 if Q17C==3
replace free_vote_choice= 2 if Q17C==4

gen how_democratic=0 if Q42!=.  & Q42!=-1  & Q42!=9
replace how_democratic=1 if Q42==3
replace how_democratic=2 if Q42==4
label var how_democratic "Believe that Senegal is a functioning democracy"

gen satisfaction_democracy = 0 if Q43!=. & Q43!=-1 & Q43!=9
replace satisfaction_democracy = 1 if Q43==3
replace satisfaction_democracy = 2 if Q43==4
label var satisfaction_democracy "Satisfaction democracy"

gen checks_balances =0 if Q36!=. &  Q36!=-1 & Q36!=9
replace checks_balances =1 if Q36==1 |  Q36==2

gen checks_balances_strong =0 if  Q36!=. &  Q36!=-1 & Q36!=9
replace checks_balances_strong =1 if Q36==1

gen against_govt_ban_org=0 if Q19!=-1 & Q19!=. & Q19!=9
replace against_govt_ban_org=1 if Q19==3| Q19==4

gen against_govt_ban_org_str=0 if Q19!=-1 & Q19!=. &Q19!=9
replace against_govt_ban_org_str=1 if Q19==4

gen against_president_discretion =0 if Q40!=. & Q40!=-1 &  Q40!=9
replace against_president_discretion =1 if Q40==3 |  Q40==4

gen against_pres_discr_strong =0 if Q40!=. & Q40!=-1 & Q40!=9
replace against_pres_discr_strong =1 if Q40==4
drop Q40

gen term_limits =0 if Q41!=.  & Q41!=-1  & Q41!=9 
replace term_limits  =1 if Q41 ==1 | Q41 ==2

gen term_limits_strongly =0 if Q41!=.  & Q41!=-1 & Q41!=9 
replace term_limits_strongly  =1 if Q41 ==1
drop Q41

gen media_accountability =0 if Q38!=. &  Q38!=-1 & Q38!=9
replace media_accountability =1 if Q38==1 | Q38==2

gen media_accountability_strong =0 if Q38!=. &  Q38!=-1 & Q38!=9
replace media_accountability_strong =1 if Q38==1
label var media_accountability "Believe media should check government"
drop Q38

gen opp_parties_criticize =0 if Q37!=. &  Q37!=-1 & Q37!=9
replace opp_parties_criticize =1 if Q37==1 | Q37==2

gen opp_parties_crit_str =0 if Q37!=. &  Q37!=-1 & Q37!=9
replace opp_parties_crit_str =1 if Q37==1


gen against_one_party_rule =0 if Q31A!=. & Q31A!=-1 & Q31A!=9
replace against_one_party_rule =1 if Q31A == 1 | Q31A==2

gen a_one_party_rule_strong =0 if Q31A!=. & Q31A!=-1 & Q31A!=9
replace a_one_party_rule_strong =1 if Q31A == 1 

gen reject_military_rule =0 if Q31B!=. & Q31B!=-1 & Q31B!=9
replace reject_military_rule =1 if Q31B == 1 | Q31B==2

gen r_mil_rule_str =0 if Q31B!=. & Q31B!=-1 & Q31B!=9
replace r_mil_rule_str =1 if Q31B == 1

gen reject_one_man_rule =0 if Q31C!=. & Q31C!=-1 &  Q31C!=9
replace reject_one_man_rule =1 if Q31C == 1 | Q31C==2

gen r_one_man_r_strongly =0 if Q31C!=. & Q31C!=-1 & Q31C!=9
replace r_one_man_r_strongly =1 if Q31C == 1 

 
gen election_choice_leaders = 0 if Q34!=.  & Q34!=-1  & Q34!=9
replace election_choice_leaders = 1 if Q34==1  | Q34==2

gen election_choice_leaders_str = 0 if Q34!=.  & Q34!=-1  & Q34!=9
replace election_choice_leaders_str = 1 if Q34==1 

gen supports_democracy=0 if Q32!=. & Q32!=-1
replace supports_democracy=1 if Q32==3
label var supports_democracy "Supports democracy"


gen newspaper_free=0 if Q20!=-1 & Q20!=. &Q20!=9
replace newspaper_free=1 if Q20==1 | Q20 ==2 

gen newspaper_free_str=0 if Q20!=-1 & Q20!=. &Q20!=9
replace newspaper_free_str=1 if Q20 ==1



*** Trust in different institutions ***

gen trust_president =Q59A if Q59A!=. & Q59A!=-1 & Q59A!=9

gen trust_national_assembly=Q59B if Q59B!=. &  Q59B!=-1 & Q59B!=9

gen trust_LG_council=Q59E if Q59E!=. & Q59E!=-1 & Q59E!=9

gen trust_ruling_party=Q59F if Q59F!=. & Q59F!=-1 & Q59F!=9

gen trust_opposition_party=Q59G if Q59G!=. & Q59G!=-1 & Q59G!=9
drop Q59*



*** Government performance ***


gen present_econ = Q3A - 1 if Q3A!=. & Q3A!=-1 & Q3A!=9
label var present_econ "Economic conditions"

gen personal_econ = Q3B - 1 if Q3B!=. & Q3B!=-1 & Q3B!=9
label var personal_econ "Economic conditions"

gen past_econ = Q5A - 1 if Q5A!=. & Q5A!=-1 & Q5A!=9
label var past_econ "Compare econ, past 12mths"

gen future_econ = Q6A - 1 if Q6A!=. & Q6A!=-1 & Q6A!=9
label var future_econ "Future econ (12mth)"

gen handles_economy =Q65A-1 if Q65A!=. & Q65A!=-1 & Q65A!=9
label var handles_economy "Government handles economy"

gen handles_employment=Q65C-1 if Q65C!=. & Q65C!=-1 & Q65C!=9
label var handles_employment "Government handles employment"

gen handles_inflation=Q65D-1 if Q65D!=. & Q65D!=-1 & Q65D!=9
label var handles_inflation "Government handles inflation"

gen handles_inequality=Q65E-1 if Q65E!=. & Q65E!=-1 & Q65E!=9
label var handles_inequality "Government handles inequality"

gen handles_health=Q65G-1 if Q65G!=. & Q65G!=-1 & Q65G!=9
label var handles_health "Government handles health provision"

gen handles_education=Q65H-1 if Q65H!=. & Q65H!=-1 & Q65H!=9
label var handles_education "Government handles education provision"

gen handles_water=Q65I-1 if Q65I!=. & Q65I!=-1 & Q65I!=9
label var handles_water "Government handles water provisoon"
drop Q65*

gen loc_gov_handles_roads=Q66A-1 if Q66A!=. & Q66A!=-1 & Q66A!=9
label var loc_gov_handles_roads "Local government handles roads"

gen loc_gov_handles_markets=Q66B-1 if Q66B!=. & Q66B!=-1 & Q66B!=9
label var loc_gov_handles_markets "Local government handles markets"

gen loc_gov_handles_health=Q66C-1 if Q66C!=. & Q66C!=-1 & Q66C!=9
label var loc_gov_handles_health "Local government handles health in restaurants"

gen loc_gov_handles_clean=Q66D-1 if Q66D!=. & Q66D!=-1 & Q66D!=9
label var loc_gov_handles_clean "Local government handles community cleaning"

gen loc_gov_handles_land=Q66E-1 if Q66E!=. & Q66E!=-1 & Q66E!=9
label var loc_gov_handles_land "Local government handles land issues"
drop Q66*

gen performance_president = Q71A-1 if Q71A!=. & Q71A!=-1 & Q71A!=9
label var performance_president "Approves President perfomance"
 
gen performance_mp  = Q71B-1 if Q71B!=. & Q71B!=-1 & Q71B!=9
label var performance_mp "Approves MP perfomance"

gen performance_LG_councilor  = Q71C-1 if Q71C!=. & Q71C!=-1 & Q71C!=9
label var performance_LG_councilor "Approves LG councilor perfomance"
drop Q71*


gen MP_listen = Q62A if Q62A !=. & Q62A !=-1 & Q62A !=9
label var  MP_listen "MPs listen to people's interests"

gen LG_councilor_listen = Q62B if Q62B !=. & Q62B !=-1 & Q62B !=9
label var  LG_councilor_listen "LG Counncilors listen to people's interests"
drop Q62*

gen corruption_president = Q60A if Q60A !=. &  Q60A !=-1 &  Q60A !=9
label var corruption_president "Very corrupt president office"

gen corruption_MP = Q60B if Q60B !=. &  Q60B !=-1 &  Q60B !=9
label var corruption_MP "Very corrupt MPs"

gen corruption_LG_councilors = Q60D if Q60D  !=. &  Q60D  !=-1 &  Q60D  !=9
label var corruption_LG_councilors "Very corrupt LG councilors"

gen corruption_government_officials = Q60C if Q60C !=. &  Q60C !=-1 &  Q60C !=9 
label var corruption_government_officials "Very corrupt government officials"


gen corr_pres_dk = Q60A == 9  if Q60A !=. &  Q60A !=-1
gen corr_mp_dk = Q60B == 9  if Q60B !=. &  Q60B !=-1
gen corr_lg_dk = Q60D == 9  if Q60D !=. &  Q60D !=-1
gen corr_gov_dk = Q60C == 9  if Q60C !=. &  Q60C !=-1


drop Q60*

drop EANUMB_AB-Q117

